/* Foundation v2.2 http://foundation.zurb.com */
jQuery(document).ready(function ($) {

	/* Use this js doc for all application specific JS */

	/* TABS --------------------------------- */
	/* Remove if you don't need :) */

	function activateTab($tab) {
		var $activeTab = $tab.closest('dl').find('a.active'),
				contentLocation = $tab.attr("href") + 'Tab';

		//Make Tab Active
		$activeTab.removeClass('active');
		$tab.addClass('active');

    	//Show Tab Content
		$(contentLocation).closest('.tabs-content').children('li').hide();
		$(contentLocation).css('display', 'block');
	}

	$('dl.tabs').each(function () {
		//Get all tabs
		var tabs = $(this).children('dd').children('a');
		tabs.click(function (e) {
			activateTab($(this));
		});
	});

	if (window.location.hash) {
		activateTab($('a[href="' + window.location.hash + '"]'));
	}

	/* DROPDOWN NAV ------------- */

	var lockNavBar = false;
	$('.nav-bar a.flyout-toggle').live('click', function(e) {
		e.preventDefault();
		var flyout = $(this).siblings('.flyout');
		if (lockNavBar === false) {
			$('.nav-bar .flyout').not(flyout).slideUp(500);
			flyout.slideToggle(500, function(){
				lockNavBar = false;
			});
		}
		lockNavBar = true;
	});
    $('.nav-bar>li.has-flyout').hover(function() {
      $(this).children('.flyout').show();
    }, function() {
      $(this).children('.flyout').hide();
  })

  $('ul.menu li.has-flyout').hover(
        function () {
            $(this).find('.flyout').stop(true, true).fadeIn('fast');
            $(this).addClass('hover');
        },
	    function () {
	        $(this).find('.flyout').stop(true, true).fadeOut('fast');
	        $(this).removeClass('hover');
	    });

	    $('ul.menu li.has-dropdown').hover(
        function () {
            $(this).find('ul:first').stop(true, true).fadeIn('fast');
            $(this).addClass('hover');
        },
	    function () {
	        $(this).find('ul').stop(true, true).fadeOut('fast');
	        $(this).removeClass('hover');
	    });
});

!function ($) {
    "use strict"

    var toggle = '[data-toggle="flyout"]',
        Flyout = function (element) {
            /*
            var $el = $(element).on('click.flyout.data-api', this.toggle)
            $('html').on('click.flyout.data-api', function () { 
            $el.parent().removeClass('open')
            })
            */

            var $el = $(element).on({
                mouseenter: function () {
                    toggle
                },
                mouseleave: function () { 
                    $el.parent().removeClass('open')
                }
            })
        }

        Flyout.prototype = {
            constructor: Flyout,
            toggle: function (e) {
                var $this = $(this),
                    selector = $this.attr('data-target'),
                    $parent,
                    isActive

                if (!selector) {
                    sele = $this.attr('href')
                    selec = selec && selec.replace(/.*(?=#[^\s]*$)/, '')
                }

                $parent = $(selector)
                $parent.length || ($parent = $this.parent())

                isActive = $parent.hasClass('open')

                clearFlyoutMenus()
                !isActive && $parent.toggleClass('open')

                return false
            }
        }

    function clearFlyoutMenus() {
        $(toggle).parent().removeClass('open')
    }

    $.fn.flyout = function (option) {
        return this.each(function () { 
            var $this = $(this),
                data = $this.data('flyout')

            if(!data)
                $this.data('flyout', (data = new Flyout(this)))
            if (typeof option == 'string')
                data[option].call($this)
        })
    }

    $.fn.flyout.Constructor = Flyout

    $(function () {
        $('body').on({
            mouseenter: function () {
                toggle;
            },
            mouseleave: function(){
                clearFlyoutMenus;
            }
        })
    })

} (window.jQuery);

$(document).ready(function () {
    $("label.inlined + input.input-text").each(function (type) {

        Event.observe(window, 'load', function () {
            setTimeout(function () {
                if (!input.value.empty()) {
                    input.previous().addClassName('has-text');
                }
            }, 200);
        });

        $(this).focus(function () {
            $(this).prev("label.inlined").addClass("focus");
        });

        $(this).keypress(function () {
            $(this).prev("label.inlined").addClass("has-text").removeClass("focus");
        });

        $(this).blur(function () {
            if ($(this).val() == "") {
                $(this).prev("label.inlined").removeClass("has-text").removeClass("focus");
            }
        });
    });
});